import type { Directive } from 'vue';

/**
 * 输入框自动聚焦
 */
export const focus: Directive = {
  async mounted(el: HTMLInputElement) {
    const input = ['INPUT', 'TEXTAREA'].includes(el.tagName)
      ? el
      : el.querySelector('input') || el.querySelector('textarea');
    await nextTick();
    input?.focus();
  },
};
